package com.six.marketing.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class RedisService {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    public void setCouponStatus(String orderId, String status, long timeout) {
        redisTemplate.opsForValue().set("COUPON_STATUS_" + orderId, status, timeout, TimeUnit.MINUTES);
    }

    public String getCouponStatus(String orderId) {
        return (String) redisTemplate.opsForValue().get("COUPON_STATUS_" + orderId);
    }

    public void removeCouponStatus(String orderId) {
        redisTemplate.delete("COUPON_STATUS_" + orderId);
    }
}
